package recommend

import (
	"context"
	"strconv"

	"mall/service/backend/api/internal/svc"
	"mall/service/backend/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateUserLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 创建Gorse User
func NewCreateUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateUserLogic {
	return &CreateUserLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateUserLogic) CreateUser(req *types.IDsReq) (*types.BaseMsgResp, error) {
	if len(req.Ids) > 0 {
		for _, v := range req.Ids {
			err := l.createGorseUserLogic(strconv.FormatUint(v, 10))
			if err != nil {
				return nil, err
			}
		}
	}
	return &types.BaseMsgResp{
		Msg: "添加成功",
	}, nil
}

func (l *CreateUserLogic) createGorseUserLogic(uid string) error {
	return l.svcCtx.GorseClient.CreateUser(
		l.svcCtx.Config.Query.GorseUrl,
		uid, "",
		"", "",
	)
}
